package ar.edu.itba.it.paw.domain;



public class User extends PersistentAttributes {
	
	private String username;
	private String password;
	private String first_name;
	private String last_name;
	private String mail;
	private boolean admin;
	
	//This constructor is used to create users before they are inserted to the database
	public User(String username, String password, String nombre, String apellido, String mail) throws IllegalArgumentException{
		this.setUsername(username);
		this.setPassword(password);
		this.setNombre(nombre);
		this.setApellido(apellido);
		this.setMail(mail);
	}
	
	private void setUsername(String username) {
		if(username != null && !username.equals("") && username.length() <= 20)
			this.username = username;
		else
			throw new IllegalArgumentException();
	}

	public String getUsername() {
		return username;
	}

	private void setPassword(String password) {
		if(password != null && !password.equals("") && password.length() >= 8)
			this.password = password;
		else throw new IllegalArgumentException();
	}

	public String getPassword() {
		return password;
	}

	private void setNombre(String nombre) {
		if(nombre != null && !nombre.equals(""))
			this.first_name = nombre;
	}

	public String getNombre() {
		return first_name;
	}

	private void setApellido(String apellido) {
		if(apellido != null && !apellido.equals(""))
			this.last_name = apellido;
		else
			throw new IllegalArgumentException();
	}

	public String getApellido() {
		return last_name;
	}

	private void setMail(String mail) {
		if(mail != null && !mail.equals(""))
			this.mail = mail;
		else
			throw new IllegalArgumentException();
	}

	public String getMail() {
		return mail;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "User [username=" + username + ", password=" + password
				+ ", nombre=" + first_name + ", apellido=" + last_name + ", mail="
				+ mail + ", userId=" + getId() + "]";
	}
	public void setAdmin(boolean admin) {
		this.admin = admin;
	}
	public boolean isAdmin() {
		return admin;
	}

}
